#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
智慧童话世界 - 快速启动
简化版启动脚本，用于快速测试和演示
"""

import os
import sys
from pathlib import Path

def print_banner():
    """打印启动横幅"""
    print("""
╔══════════════════════════════════════════════════════════════╗
║                    🌟 智慧童话世界 🌟                        ║
║                AI可选分支剧情童话书应用                       ║
║                                                              ║
║  🤖 基于 ERNIE-4.5-0.3B-Paddle 大模型                       ║
║  🧠 集成智源研究院深度科研数据                                ║
║  📡 支持MCP模型控制协议                                      ║
║  🎨 多模态交互体验 (文本/图像/语音)                          ║
╚══════════════════════════════════════════════════════════════╝
    """)

def check_files():
    """检查必要文件"""
    print("🔍 检查项目文件...")
    
    files = [
        'ai_fairy_tale_book.py',
        'web_interface.py',
        'mcp_integration.py', 
        'zhiyuan_integration.py',
        'fairy_tale_config.py',
        'story_templates.py'
    ]
    
    all_exist = True
    for file in files:
        if Path(file).exists():
            print(f"✅ {file}")
        else:
            print(f"❌ {file} - 缺失")
            all_exist = False
    
    return all_exist

def create_directories():
    """创建必要目录"""
    dirs = ['static', 'templates', 'uploads', 'logs']
    
    for dir_name in dirs:
        dir_path = Path(dir_name)
        if not dir_path.exists():
            dir_path.mkdir(exist_ok=True)
            print(f"📁 创建目录: {dir_name}")

def start_web_app():
    """启动Web应用"""
    try:
        print("\n🌐 启动Web应用...")
        print("📱 请在浏览器中访问: http://localhost:5000")
        print("🛑 按 Ctrl+C 停止应用\n")
        
        # 导入并启动Flask应用
        from web_interface import app
        app.run(host='0.0.0.0', port=5000, debug=True)
        
    except ImportError as e:
        print(f"❌ 导入错误: {e}")
        print("请确保所有依赖已安装: pip install -r requirements.txt")
    except Exception as e:
        print(f"❌ 启动错误: {e}")

def main():
    """主函数"""
    print_banner()
    
    # 检查文件
    if not check_files():
        print("\n❌ 缺少必要文件，请确保项目完整")
        return
    
    # 创建目录
    create_directories()
    
    # 启动应用
    start_web_app()

if __name__ == "__main__":
    main()